public class Test2 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 判断岛屿数量
     * @param grid char字符型二维数组 
     * @return int整型
     */
    public int count;
    public int solve (char[][] grid) {
        // write code here
        int num = 0;
        boolean[][] flag = new boolean[grid.length][grid[0].length];
        for(int i = 0; i < grid.length; i++) {
            for(int j = 0; j < grid[i].length; j++) {
                count = 0;
                if(grid[i][j] == 1) {
                    isOne(flag, grid, i, j);
                }
                if(count >= 2) {
                    num++;
                }
            }
        }
        return num;
    }
    public void isOne(boolean flag[][], char[][] grid, int row, int col) {
        if(row < 0 || row >= grid.length || col < 0 || col >= grid[row].length) {
            return;
        }
        if(flag[row][col] == true|| grid[row][col] == 0) {
            return;
        }
        if(flag[row][col] == false) {
            flag[row][col] = true;
        }
        count++;
        isOne(flag, grid, row-1, col);
        isOne(flag, grid, row+1, col);
        isOne(flag, grid, row, col-1);
        isOne(flag, grid, row, col+1);
    }
}